﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DnaServiceLib
{
    public class DnaPerson
    {
        public System.Guid Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public char? Gender { get; set; }
        public Guid? FatherDnaPersonId { get; set; }
        public Guid? MotherDnaPersonId { get; set; }
        public int FatherUserConfidenceLevel { get; set; }
        public int MotherUserConfidenceLevel { get; set; }
        public int FatherDnaVerificationLevel { get; set; }
        public int MotherDnaVerificationLevel { get; set; }
        public string FullName
        {
            get
            {
                return String.Format("{0} {1}", FirstName, LastName);
            }
        }

        public bool SaveChanges()
        {
            using (DnaDataLib.DnaGedDataContext DnaDc = new DnaDataLib.DnaGedDataContext())
            {
                DnaDataLib.DnaPerson dnaPerson = DnaDc.DnaPersons.Where(w => w.Id == Id).FirstOrDefault();
                if (dnaPerson != null)
                {
                    dnaPerson.FirstName = FirstName;
                    dnaPerson.LastName = LastName;
                    if (Gender != null && (Gender == 'M' || Gender == 'F'))
                    {
                        dnaPerson.Gender = Gender;
                    }
                    if (FatherDnaPersonId != null)
                    {
                        dnaPerson.FatherDnaPersonId = FatherDnaPersonId;
                    }
                    if (MotherDnaPersonId != null)
                    {
                        dnaPerson.MotherDnaPersonId = MotherDnaPersonId;
                    }
                    DnaDc.SubmitChanges();
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        public override string ToString()
        {
            return String.Format("{0} {1}", FirstName, LastName);
        }
    
    }


}
